<?php
class App_User_Form_AdminRoleEdit extends Main_Form
{
	/**
     * @var array
     */
    protected $_decoratorsForm  = array(
        'PrepareElements',
        array('ViewScript', array('viewScript' => '_form/admin-role-edit.phtml')),
    );
	
	/**
	 * @return void
	 */
	public function init()
	{
		parent::init();
		
		$this->setMethod('post');
		$this->setDecorators($this->_decoratorsForm);
		
		$this->addElement('hidden', 'old_code', array(
			'order'	=> 10,
			'decorators' => $this->_decoratorsHidden
		));
		
		$this->addElement('text', 'code', array(
			'label'	=> 'Код',
			'required' => true,
			'order'	=> 20,
			'validators' => array(
				array('validator' => 'StringLength', 'options' => array(2, 100)),
				array(
					'validator' => 'UniqueItem', 'options' => array (
                    	'App_User_Service_Role', 'old_code', null,
                        'Роль с таким кодом уже существует' )
                )
			)
		));
		
		$this->addElement('text', 'name', array(
			'label'	=> 'Название',
			'required' => true,
			'order'	=> 30,
		));
		
		$this->addElement('submit', 'addButton', array(
			'label' => 'Сохранить',
			'order'	=> 40,
		));
	}
	
	/**
	 * @param array $data
     * @return Main_Form
     */
    public function setFormValues($data)
    {
		$data['old_code'] = $data['code'];    	
    	return parent::setFormValues($data);
    }

}